home *** CD-ROM | disk | FTP | other *** search
/ AI Game Programming Wisdom / AIGameProgrammingWisdom.iso / SourceCode / 04 Pathfinding and Movement / 05 Hancock / NodeAndLink.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-09-17  |  4.4 KB  |  111 lines

  1.  
  2. class PathNode {
  3. public:
  4.     friend class NodeMap;
  5.     
  6.     
  7.     enum NodeFlags{
  8.         flagNodeGround    = 0x0001, //node is on the ground
  9.         flagNodeHide     = 0x0002, //good hiding place
  10.  
  11.         flagNodeSnipe      = 0x0008, //good sniping place
  12.         
  13.         flagNodeCrouch    = 0x00010, //need to be in crouch state
  14.         flagNodeLedgeHang = 0x00020, //need to hang on a ledge
  15.         
  16.         flagNodeStairs    = 0x00100, //node is on stairs
  17.         flagNodeElevator    = 0x00200, //node is on an elevator
  18.         flagNodeSwitch        = 0x00400, //node is next to a switch    
  19.     };
  20.     
  21.     enum RegionType { Connected = 0, NoDoor, NoJump, NoElevator, MaxTypes };
  22.     
  23.     CPathNode() : flags(0), radius(1.5f), elevatorFloor(0), theta(0.0f), pathSession(0){
  24.         for (int i=0; i < MaxTypes; i++) regions[i] = 0;
  25.     }
  26.  
  27.     explicit PathNode(const Vector3 &p, int flag = 0) : pos(p), flags(flag), radius(1.5f), elevatorFloor(0), pathSession(0),
  28.         prevLink(NULL), theta(0.0f), {
  29.         for (int i=0; i < MaxTypes; i++) regions[i] = 0;
  30.     }
  31.     
  32.     Vector3 pos;
  33.     int flags;
  34.     std::string name; //an optional name
  35.     std::vector<PathLink> links;
  36.     int EntityID; //the ID for an elevator or switch
  37.     int    elevatorFloor; //if the node is on an elevator, which floor it is on
  38.     float radius; //radius within which we can be considered "at this node"
  39.     
  40.     //These functions are not commutative, i.e. n1->PathExists(n2) does not necessarily imply n2->PathExists(n1)
  41.     bool PathExists(const CPathNode *destination, const Character *pChar = NULL) const; //returns true if a path exists from this node to destination that can be travelled by pChar
  42.     bool NoDoorsBetween(const CPathNode *destination) const; 
  43.     bool NoElevatorsBetween(const CPathNode *destination) const; //returns true if destination can be reached from this node without using an elevator
  44.     bool ReachableWithoutJumping(const CPathNode *destination) const; //returns true if destination can be reached from this node without jumping
  45.     
  46.     ~CPathNode();
  47.     const Elevator *GetElevator() const;
  48.     
  49.     //Get and Set the regions used by the region extraction algorithm
  50.     unsigned char GetRegion(RegionType t) const {return regions[t];}
  51.     void SetRegion(RegionType t, unsigned char r) {regions[t] = r;}
  52.     
  53.     float    TotalCost() const {return searchCost + futureCost;}
  54.     void    ProcessForPath(PathNodePriorityQueue &pq, const CPathLink *parent) const;
  55. protected:
  56.     unsigned char regions[MaxTypes];
  57.     
  58.     //reserved for path search purposes
  59.     mutable bool mOpen; //whether we're currently on the open list
  60.     mutable int pathSession;
  61.     mutable float searchCost; //the cost so far to reach this node
  62.     mutable float futureCost;    //the estimated cost to the goal from here
  63.     mutable const PathLink *prevLink;
  64. };
  65.  
  66. class PathLink {
  67. public:
  68.     friend class NodeMap;
  69.     
  70.     enum {
  71.         flagLinkReliable        = 0x000001, //this link has been verified as passable
  72.             flagLinkCrouch            = 0x000002,    //we must actively crouch to follow this link
  73.             flagLinkDoor            = 0x000004,    //there's a door on the link
  74.             flagLinkJump            = 0x000008, //must jump to cross this link
  75.             
  76.             flagLinkNearCliff        = 0x000020, //danger of falling off a cliff if going outside fat link
  77.             flagLinkRun                = 0x000040, //force the character to run on this link
  78.             flagLinkSlow            = 0x000080, //force the character to sneak along this link
  79.             
  80.             flagLinkClimb            = 0x000200, //the AI needs to do an auto-climb somewhere on this link
  81.             
  82.             flagLinkSaveMask        = 0x00FFFF, //only save flags that mask with this
  83.             flagLinkNoShortcut        = 0x010000, //the AI can not shortcut (rubberband) this link
  84.             flagLinkElevator        = 0x020000,    //the link goes between elevator floors
  85.     };
  86.     
  87.     int flags;
  88.     
  89.     
  90.     PathLink(int flag = 0) : flags(flag), origin(NULL), next(NULL), dist(0), alwaysAvailable(true), reliability(1.0f){}
  91.     PathLink(PathNode *start, PathNode *end, int flag = 0);
  92.     
  93.     bool CanBeShortcut() const;
  94.     const PathNode *Start() const {return origin;}
  95.     const PathNode *End() const {return next;}
  96.     PathNode *EndNonConst() const {return next;}
  97.     PathNode *StartNonConst() const {return origin;}
  98.     const PathLink *GetReturnLink() const; //returns the link going in the opp. direction, NULL if no return link exists
  99.     
  100.     const Door* GetDoor() const;
  101.     bool CanITravelLink(const CEntityCharacter *me);
  102.     ~PathLink(){}
  103.     float Distance() const {return dist;}
  104.     
  105. protected:
  106.     float dist;
  107.     int    doorID;            //the ID of the door if one exists on this link
  108.     CPathNode *origin; //the origin node of the link (do we need to keep this?)
  109.     CPathNode *next; //the node where the link is headed
  110. };
  111.